<template>
	<view class="user">
		<!-- 头部 -->
		<view class="user-wrap" >
			<view class="setting iconfont icon31shezhi"></view>
			<view class="info">
				<image @click="clickUser"  class="avatar" mode="aspectFill" :src="userInfo.headPicUrl"></image>
				<view  @click="clickUserName" class="nickname">{{ userInfo.nickName }}</view>
			</view>
		</view>

		<!-- 订单状态 -->
		<view class="order-status">
			<view class="status-wrap">
				<!-- 单元格 -->
				<view class="cell">
					<view class="cell-left">
						<image class="cell-icon" src="/static/images/user/icon-order.png" mode="aspectFill"></image>
						<view class="cell-text">全部浏览</view>
					</view>
					<view class="iconfont iconmore1"></view>
				</view>

				<!-- 订单状态 -->
				<view class="status-list">
					<view class="status-item" hover-class="btn-hover" v-for="(item, index) in orderStatusList" :key="index">
						<view class="item-icon" :class="item.icon"></view>
						<view class="item-text">{{ item.name }}</view>
					</view>
				</view>
			</view>
		</view> 

		<!-- 用户服务 -->
		<view class="com-item">
			<view class="com-wrap"> 
				<view class="cell" >
					<view class="cell-left">
						<image class="cell-icon" src="/static/images/user/icon-help.png" mode="aspectFill"></image>
						<view class="cell-text"> 帮助中心</view>
					</view>
					<view class="iconfont iconmore1"></view>
				</view>
				<view class="cell" @click="logOut()">
					<view class="cell-left">
						<image class="cell-icon" src="/static/images/user/icon-about.png" mode="aspectFill"></image>
						<view class="cell-text"> 退出</view>
					</view>
					<view class="iconfont iconmore1"></view>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script> 
import {mapState,mapMutations} from 'vuex';
import {  api,profile } from '@/app/api.js'  
import { encrypt,decrypt } from "@/lib/jsencrypt";
import comNav from './components/com-nav.vue'
export default {
	components: {
		comNav
	},
    computed: {  ...mapState(['token','roles','uuid']),},
	data() {
		return {
			userInfo: {
				headPicUrl: '/static/images/user/avatar.jpg',
				nickName: '史蒂芬.林'
			},
			orderStatusList: [
				{ name: '已关注', icon: 'iconfont icon31daifukuan', status: 10 }, 
				{ name: '我的足迹', icon: 'iconfont icon31daishouhuo', status: 40 },
				{ name: '待评价', icon: 'iconfont icon31daipingjia', status: 50 }, 
			],
			currentIndex: 0,  
			 
		};
	},
	onLoad() {
		var th = this; 
		profile().then(data=>{
					 console.log("用户信息: ",data.data);
					 var tmp = data.data
					 if(tmp){
						 th.userInfo.nickName  = tmp.nickName
						 th.userInfo.headPicUrl  = tmp.avatar
						 uni.setStorageSync('nickName',tmp.nickName)
						 uni.setStorageSync('avatar',tmp.avatar)
					 }
					 // admin:false 

		})
	}, 
	methods:{  
		clickUser(){  
			if(this.checkLogin()) return;
			uni.navigateTo({url:'/app/user/uploadAvatar'}) 
		},
		clickUserName(){
			if(this.checkLogin()) return;
			uni.navigateTo({url:'/app/user/updateName'}) 
		},
		logOut(){
		    var th = this	
			api("/logout",{ }).then(data=>{ 
				 if(data.code == 500){
				 	uni.showToast({title: data.msg,icon:'none',duration: 2000})  
				 }else{
				     uni.showToast({title: "成功退出",icon:'none',duration: 1000})
				     th.$store.state.roles =  "";
				     th.$store.state.token =  ""; 
				     uni.setStorageSync('token',"")
				     setTimeout(() => {
				     	 uni.switchTab({url: "/app/index",});
				      }, 1000);
				 }
			})
		}
	}
};
</script>

<style lang="scss">
page {
	background: #f2f2f2;
} 
.user {
	.user-wrap {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 50vw;
		padding: 30rpx;
		z-index: 9;
		border-radius: 0 0 20% 20%;
		background: url('https://handsel.oss-cn-shenzhen.aliyuncs.com/1588938371592.jpg') no-repeat;
		background-size: cover;
		.setting {
			color: #fff;
			position: absolute;
			top: 60rpx;
			left: 60rpx;
			font-size: 50rpx;
		}
		.info {
			position: absolute;
			text-align: center;
			.avatar {
				width: 150rpx;
				height: 150rpx;
				border-radius: 50%;
			}
			.nickname {
				color: #fff;
				font-size: 28rpx;
			}
		}
	}
	.order-status {
		padding: 0 20rpx;
		margin-top: -10vw;
		.status-wrap {
			border-radius: 25rpx;
			overflow: hidden;
			.status-list {
				display: flex;
				justify-content: space-evenly;
				align-items: center;
				background: #fff;
				padding-top: 30rpx;
				padding-bottom: 30rpx;
				.status-item {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					.item-icon {
						line-height: 1;
						font-size: 65rpx;
						color: #bbb;
					}
					.item-text {
						font-size: 28rpx;
						color: #666;
						margin-top: 5rpx;
					}
				}
			}
		}
	}
	.com-item {
		padding-left: 20rpx;
		padding-right: 20rpx;
		margin-top: 20rpx;
		.com-wrap {
			border-radius: 25rpx;
			overflow: hidden;
		}
	}
	.cell {
		height: 80rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #fff;
		border-bottom: 1px solid #f8f8f8;
		&:active {
			background: #f2f2f2;
		}
		&:last-child {
			border-bottom: none !important;
		}
		.cell-left {
			display: flex;
			align-items: center;
			.cell-icon {
				width: 50rpx;
				height: 50rpx;
			}
			.cell-text {
				color: #666;
				font-size: 28rpx;
				margin-left: 20rpx;
			}
		}
		.iconfont {
			font-size: 40rpx;
			color: #999;
		}
	}
}
</style>
